﻿using Alos.Entity;
using Alos.IRepository;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Alos.Repository
{
    public class ReClassSignRepository : BaseRepository<ReClassSign>, IReClassSignRepository
    {
        /// <summary>
        /// 根据备课编号获取当前该课堂上学生标记
        /// </summary>
        /// <param name="id">备课编号</param>
        /// <param name="ReType">类型  上课点评0 ， 结束上课评论1</param>
        /// <returns></returns>
        public IEnumerable<ReClassSign> GetReClassSign(int id, int ReType)
        {
            var sql = Sql.Builder.Append(" SELECT * FROM ReClassSign  WHERE LessionID=@0 and ReType=@1", id, ReType);

            return DBContext.Query<ReClassSign>(sql);
        }
        /// <summary>
        /// 添加学生课堂标记
        /// </summary>
        /// <param name="reclasssign">学生课堂标记</param>
        /// <returns></returns>
        public int CreatReClassSign(ReClassSign reclasssign)
        {
            return Convert.ToInt32(reclasssign.Insert());
        }        
        /// <summary>
        /// 根据备课编号和学生ID删除学生课堂标记
        /// </summary>
        /// <param name="LessionID">备课编号</param>
        /// <param name="StudentID">学生ID</param>
        /// <param name="SignContent">类型 点赞0,一般1，差评2</param>
        /// <param name="ReType">类型  课堂点评0，结束上课点评1</param>
        /// <returns></returns>
        public int DeleteReClassSign(int LessionID, int StudentID, int SignContent, int ReType)
        {
            var sql = Sql.Builder.Append(@"DELETE ReClassSign WHERE Id IN (SELECT TOP 1 Id FROM ReClassSign WHERE LessionID=@0 AND StudentID=@1 AND SignContent=@2 AND ReType=@3", LessionID, StudentID, SignContent, ReType);
            return DBContext.Execute(sql);
        }
    }
}
